package com.frank.utils;

import java.util.ArrayList;

/**
 * @Description 单向链表
 * @Author zhoujr
 * @Data 2024/11/23 14:45
 */
public class ListNode {
    public int val;
    public ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

    public static ListNode toListNode(ArrayList<Integer> list) {
        ListNode last = null;
        for (int i = list.size() - 1; i >= 0; i--) {
            int num = list.get(i);
            last = new ListNode(num, last);
        }
        return last;
    }

}
